package com.tojabo.swing.seven_listener;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.EventQueue;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JFrame;

public class KeyboardActionExit extends JFrame {

	private static final long serialVersionUID = 1L;

	public KeyboardActionExit() {
		addKeyListener(new KeyAdapter() {
			public void keyPressed(KeyEvent event) {
				if (event.getKeyCode() == KeyEvent.VK_ESCAPE) {
					System.out.println("kan kan ");
					System.exit(0);
				}
			}
		});
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				JFrame frame = new KeyboardActionExit();
				frame.setSize(400, 300);
				JButton but = new JButton("看看");
				Container contentPane = frame.getContentPane();
				//contentPane.add(but, BorderLayout.NORTH);
				
				frame.setVisible(true);
				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			}
		});
	}

}
